﻿using blackhouse.WebNemo.Business;
using blackhouse.WebNemo.Business.Groups;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace blackhouse.WebNemo.Web {
    public partial class GroupListing : System.Web.UI.Page {

        #region Fields

        private int groupId;

        #endregion

        #region Event Handlers

        protected override void OnPreInit(EventArgs e) {
            base.OnPreInit(e);

            WebNemoUtils.ChangeSkinForCurrentMode(this);
        }

        protected override void OnLoad(EventArgs e) {
            base.OnLoad(e);

            string s = Request.QueryString["groupId"];
            if (!string.IsNullOrEmpty(s) && Int32.TryParse(s, out this.groupId)) {
                IGroup group = Factory.Instance().GetGroup(groupId);
                if (group.Exists) {
                    this.Records1.Group = group;
                    this.Records1.DataBind();
                    NemoUrl url = NemoUrl.Get();
                    url.View = NemoUrlView.EditRecord;
                    url.GroupId = this.groupId;
                    url.RecordId = 0;

                    if (group.Type == GroupType.Table)
                        this.lnkAdd.NavigateUrl = url.GetUrl();
                    else
                        this.lnkAdd.Visible = false;
                    url.View = NemoUrlView.RecordList;
                    this.lnkRefresh.NavigateUrl = url.GetUrl();

                    if (!String.IsNullOrEmpty(Request["translate"]))
                        this.lnkAdd.Visible = false;

                    this.ltlGroupName.Text = this.Records1.GroupName;
                }
            }
            bool isPopup = Request["ispopup"] == "1";
            if (isPopup)
                this.lnkClose.Attributes.Add("data-type", "close-popup");
            else {
                this.lnkClose.NavigateUrl = Request["returnUrl"];
            }
        }

        #endregion

    }
}